#define _CRT_SECURE_NO_WARNINGS 1

class Solution
{
    long prev = LONG_MIN;
public:
    bool isValidBST(TreeNode* root)
    {
        if (root == nullptr) return true;
        bool left = isValidBST(root->left);
        bool cur = false;
        if (root->val > prev)
        {
            cur = true;
            prev = root->val;
        }
        bool right = isValidBST(root->right);
        return left && cur && right;


    }
};